const app = getApp();
let ServiceUrl = app.globalData.ServiceUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
      require_date:'',
      require_time:'',
      start_name:'',
      to_name:'',
      service_type:'',
      pay_get:'',
      order_id:'',
      user_id:''
  },
  /**
   * 忽略
   */
ignore: function(){
  console.log('忽略')
  wx.showModal({
        title: '提示',
        content: '您确定要忽略吗？',
        showCancel: true, //是否显示取消按钮-----》false去掉取消按钮
        cancelText: "否", //默认是“取消”
        cancelColor: 'skyblue', //取消文字的颜色
        confirmText: "是", //默认是“确定”
        confirmColor: 'skyblue', //确定文字的颜色
        success: function(res) {
            if (res.cancel) {//点击取消
                console.log("您点击了取消")
            } else if(res.confirm){//点击确定
                console.log("您点击了确定")
                wx.redirectTo({
                  url: '../index/home',
                })
            }
        }
   })
},
/**
 * 接单 
 */
take: function(){
  console.log('接单')
  let that = this
  wx.showModal({
    title: '提示',
    content: '是否确认接单？',
    showCancel: true, //是否显示取消按钮-----》false去掉取消按钮
    cancelText: "否", //默认是“取消”
    cancelColor: 'skyblue', //取消文字的颜色
    confirmText: "是", //默认是“确定”
    confirmColor: 'skyblue', //确定文字的颜色
    success: (res) => {
      if (res.confirm) {
        that.takeOrder();
      }else{
        wx.redirectTo({
          url: '../index/index',
        })
      }
    },
  });
},
/**
 * 接单请求 
 */
takeOrder:function(){
  let that = this
  wx.request({
    url: ServiceUrl + 'takeConfirm',
    data: {
      order_id: that.data.order_id,
      user_id: that.data.user_id
    },
    method:"post",
    success: function(res){
      console.log(res)
      if(res.data.state == 200){
        wx.showToast({
          title: res.data.msg,
        });
        setTimeout(() => {
          wx.redirectTo({
            url: '../index/home',
          })
        }, 2000); 
      }else if(res.data.state == 400){
        wx.showModal({
          title: '提示',
          content: res.data.msg,
          showCancel: false, //是否显示取消按钮-----》false去掉取消按钮
          confirmColor: 'skyblue', //确定文字的颜色
          success: (res) => {
            if (res.confirm) {
              wx.redirectTo({
                url: '../index/index',
              })
            }
          },
        });
      }
    },
    fail: function(){
      console.log('发送请求失败')
    }
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    console.log(wx.getStorageSync('uid'))
    let that = this
    if(wx.getStorageSync('uid') == '' || wx.getStorageSync('uid') == null){
      wx.showModal({
            title: '提示',
            content: '请先登录',
            showCancel: false, //是否显示取消按钮-----》false去掉取消按钮
            confirmColor: 'skyblue', //确定文字的颜色
            success: function(res) {
                if(res.confirm){//点击确定
                    console.log("您点击了确定")
                    wx.redirectTo({
                      url: '../index/index',
                    })
                }
            }
       })
    }
    
    that.setData({
      order_id: options.order_id,
      user_id: wx.getStorageSync('uid')
    })
    if(options.user_id != '' || options.user_id != 'undefined'){
      that.setData({user_id: options.user_id})
    }
    console.log(that.data.order_id)
    wx.request({
      url: ServiceUrl + 'takeOrderInfo',
      data: {
        order_id: that.data.order_id
//        order_id: '20201110985652'
      },
      method: "post",
      success: function(res){
        console.log(res)
        that.setData({
          require_date: res.data.data.require_date,
          require_time: res.data.data.require_time,
          start_name: res.data.data.start_name,
          to_name: res.data.data.to_name,
          service_type: res.data.data.service_type,
          pay_get: res.data.pay_get
        })
      },
      fail: function(){
        console.log('发送请求失败')
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})